package com.hzit.hzb.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hzit.common.result.R;
import com.hzit.hzb.base.util.JwtUtils;
import com.hzit.hzb.core.pojo.entity.Borrower;
import com.hzit.hzb.core.pojo.vo.BorrowerApprovalVO;
import com.hzit.hzb.core.pojo.vo.BorrowerDetailVO;
import com.hzit.hzb.core.pojo.vo.BorrowerVO;
import com.hzit.hzb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author hbxfwf
 * @since 2024-08-27
 */
@RestController
@RequestMapping("/admin/core/borrower")
@Api(tags = "借款人管理接口")
@Slf4j
public class AdminBorrowerController {

	@Autowired
	private BorrowerService borrowerService;

	@GetMapping("/getPageList/{page}/{limit}")
	@ApiOperation("根据查询关键字分页查询借款人信息")
	public R getPageList(@PathVariable("page") @ApiParam(value="当前页",required = true,defaultValue = "1") Long page,
	                     @PathVariable("limit") @ApiParam(value="每页大小",required = true,defaultValue = "5") Long limit,
	                     @RequestParam("keywords") @ApiParam(value = "关键字",required = false) String keywords){
		// 1.1 进行分页带条件查询
		IPage<Borrower> borrowerPageModel = borrowerService.getPageList(page,limit,keywords);
		// 1.2 将查询结果返回给前端
		return R.ok().data("pageModel",borrowerPageModel);
	}

	// 2. 根据借款人id查询借款人详细信息
	@GetMapping("/show/{id}")
	@ApiOperation("根据借款人id查询借款人详细信息")
	public R show(@PathVariable("id") @ApiParam(value = "借款人id",required = true) Long id){
		BorrowerDetailVO borrowerDetailVO = borrowerService.getDetailsById(id);
		return R.ok().data("borrowerDetailVO",borrowerDetailVO);
	}

	// 3. 用户审核
	@PostMapping("/approval")
	public R approval(@RequestBody BorrowerApprovalVO vo){
		borrowerService.approval(vo);
		return R.ok().message("审批完成");
	}
}

